﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.DXErrorProvider;

namespace Warehouse_Management.New
{
    public partial class frmKho : DevExpress.XtraEditors.XtraForm
    {
        public frmKho()
        {
            InitializeComponent();
        }
        public KhoHang KHO = new KhoHang();
        public enum OpenType
        {
            IsEdit,
            IsNew,
        }
        public OpenType type;
        public bool isSave = false;
        private void frmKho_Load(object sender, EventArgs e)
        {
            set();
        }
        private void set()
        {
            if (KHO != null)
            {
                txtGhiChu.Text = KHO.GhiChu;
                txtMaKho.Text = KHO.MaKho;
                txtDiaChi.Text = KHO.DiaChi;
                txtTenKho.Text = KHO.TenKho;
            }
        }
        private void get()
        {
            if (KHO == null)
                KHO = new KhoHang();
            KHO.GhiChu = txtGhiChu.Text.Trim();
            KHO.MaKho = txtMaKho.Text.Trim();
            KHO.TenKho = txtTenKho.Text.Trim();
            KHO.DiaChi = txtDiaChi.Text.Trim();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

            errorPro.ClearErrors();
            bool isValid = true;
            if (string.IsNullOrEmpty(txtMaKho.Text))
            {
                errorPro.SetError(txtMaKho, "Không được để trống mã nhà sách", ErrorType.Critical);
                isValid = false;
            }
            if (!isValid) return;
            this.get();
            isSave = true;
            this.Close();
        }
    }
}